package dao

import "go-demo/model"

// 通过id查取视频
func GetVideoByID(id int64) (model.Video, error) {
	var video model.Video
	result := Db.First(&video, id)
	if result.Error != nil {
		return video, result.Error
	}
	return video, nil
}

// 通过用户id查询视频列表
func GetVideoByUser(id int64) ([]model.Video, error) {
	var videos []model.Video
	result := Db.Where("user_id = ?", id).Find(&videos)
	if result.Error != nil {
		return videos, result.Error
	}
	return videos, nil
}

// 获取所有视频
func GetAllVideo() ([]model.Video, error) {
	var videos []model.Video
	result := Db.Find(&videos)
	if result.Error != nil {
		return videos, result.Error
	}
	return videos, nil
}
